package com.example.demo.config.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: H_tao_X
 * Date: 2022-08-01
 * Time: 19:29
 */
@Controller
@ResponseBody
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public boolean login(HttpServletRequest request,String username, String password) {
        boolean result = false;
        // 第一个 if 判断是否有数据
        if(StringUtils.hasLength(username) &&
                StringUtils.hasLength(password)) {
            // 第二个 if 判断是否相等
            if(username.equals("admin") && password.equals("admin")) {
                HttpSession session = request.getSession();
                session.setAttribute("userinfo","userinfo");
                return true;
            }
        }
        return result;
    }

    @RequestMapping("/index")
    public String index(HttpServletRequest request,String username, String password){
         int num = 10 / 0;

        return "hello,Index";
    }

    @RequestMapping("index1")
    public String index() {
        int num = 10 / 0;
        return "hello,index1";
    }

    @RequestMapping("index2")
    public String index2() {
        Object object = null;
        System.out.println(object.hashCode());
        return "hello,index2";
    }


}
